A number of changes throughout to support formats like GPX and Mapsource
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 5 Jan 2004 20:08:10 +0000 (20:08 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 5 Jan 2004 20:08:10 +0000 (20:08 +0000)
that can have more than one of (waypoints, tracks, routes) in one file.

This doesn't get it for every format (or even for MPS output) but it
helps some of our cases...

gpsbabel/defs.h
gpsbabel/gpilots.c
gpsbabel/gpx.c
gpsbabel/mapsource.c
gpsbabel/psitrex.c
gpsbabel/route.c
gpsbabel/waypt.c

index 45cad67feb32776b084b79cbca0e681a4f01d5bb..dc344205d5b5e3e5278494b44c69dffc728c6758 100644 (file)
@@ -218,6 +218,7 @@ void route_add (waypoint *);
 void route_add_wpt(route_head *rte, waypoint *wpt);
 void route_del_wpt(route_head *rte, waypoint *wpt);
 void route_add_head(route_head *rte);
+void track_add_head(route_head *rte);
 void route_disp_all(route_hdr, route_trl, waypt_cb);
 void route_free (route_head *);
 void route_flush( queue *);
index 21660b0151b897b62feb0d8bf431673caf1b274a..62eabf5438332e51a7c702b80d01ec1b3c259415 100644 (file)
@@ -219,7 +219,7 @@ data_read(void)
                         */
                        case 101:
                                track_head = route_head_alloc();
-                               route_add_head(track_head);
+                               track_add_head(track_head);
                                track_head->rte_name = xstrndup(rec->wpt.CustTrkHdr.name, sizeof(rec->wpt.CustTrkHdr.name));
                                sz = be_read32(&rec->wpt.CustTrkHdr.number);
                                tp = (Custom_Trk_Point_Type *) ((char *) pdb_rec->data + sizeof(rec->wpt.CustTrkHdr));
index 14e71db729ff36aaa00c0818c628351d1fc69432..f425b4ee0ca02deb4347051f0b407e205b881fd4 100644 (file)
@@ -355,7 +355,7 @@ gpx_start(void *data, const char *el, const char **attr)
                break; 
        case tt_trk:
                trk_head = route_head_alloc();
-               route_add_head(trk_head);
+               track_add_head(trk_head);
                in_trk++;
                break;
        case tt_trkpt:
@@ -1148,7 +1148,7 @@ gpx_waypt_pr(const waypoint *waypointp)
                        fprintf(ofd, "</desc>\n");
                }
        }
-       if (waypointp->altitude) {
+       if (waypointp->altitude != unknown_alt) {
                fprintf(ofd, "<ele>\n%f\n</ele>\n",
                         waypointp->altitude);
        }
@@ -1220,7 +1220,7 @@ gpx_track_tlr(const route_head *rte)
 static
 void gpx_track_pr()
 {
-       route_disp_all(gpx_track_hdr, gpx_track_tlr, gpx_track_disp);
+       track_disp_all(gpx_track_hdr, gpx_track_tlr, gpx_track_disp);
 }
 
 static void
@@ -1327,19 +1327,10 @@ gpx_write(void)
        fprintf(ofd, "xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\">\n");
 
         gpx_write_time( now, "time" );
-       switch(global_opts.objective) {
-               case trkdata: 
-                               gpx_track_pr();
-                               break;
-               case rtedata: 
-                               gpx_route_pr();
-                               break;
-               case wptdata: 
-                               waypt_disp_all(gpx_waypt_pr);
-                               break;
-               default:
-                             break;
-       }
+
+       waypt_disp_all(gpx_waypt_pr);
+       gpx_track_pr();
+       gpx_route_pr();
 
        fprintf(ofd, "</gpx>\n");
 }
index 3f015f91cb5a20460fcf7fbaa621641ff7720564..13ea5ddd89fb04a753abeb87f80df28c872fb5b6 100644 (file)
@@ -1221,7 +1221,7 @@ mps_track_r(FILE *mps_file, int mps_ver, route_head **trk)
 
        track_head = route_head_alloc();
        track_head->rte_name = xstrdup(trkname);
-       route_add_head(track_head);
+       track_add_head(track_head);
        *trk = track_head;
 
        while (trk_count--) {
@@ -1416,7 +1416,7 @@ mps_read(void)
 
        char            recType;
        int                     reclen;
-       int                     skipMe;
+       int                     morework;
 
        mps_ver_in = 0;         /* although initialised at declaration, what happens if there are two mapsource
                                                   input files? */
@@ -1426,57 +1426,46 @@ mps_read(void)
        printf("static icon_mapping_t icon_table[] = {\n");
 #endif
 
+       morework = 1;
+       while (morework && !feof(mps_file_in)) {
 
-       while (!feof(mps_file_in)) {
-
-               /* skip over this record, unless.... */
-               skipMe = 1;
                /* Read record length of next section */
                fread(&reclen, 4, 1, mps_file_in);
                reclen = le_read32(&reclen);
 
                /* Read the record type "flag" in - using fread in case in the future need more than one char */
                fread(&recType, 1, 1, mps_file_in);
-
-               if (recType == 'W')  {
+               switch (recType) {
+               case 'W':
                        /* Waypoint record */
                        /* With routes, we need the waypoint info that reveals, for example, the symbol type */
-                       if ((global_opts.objective == wptdata) || (global_opts.objective == rtedata)) {
-                               mps_waypoint_r(mps_file_in, mps_ver_in, &wpt);
+                       mps_waypoint_r(mps_file_in, mps_ver_in, &wpt);
 #ifdef DUMP_ICON_TABLE
-                               printf("\t{  %4u, \"%s\" },\n", icon, wpt->shortname);
+                       printf("\t{  %4u, \"%s\" },\n", icon, wpt->shortname);
 #endif
-                               skipMe = 0;
-                       }
-               }
+                       break;
 
-               if (recType == 'R')  {
+               case 'R':
                        /* Route record */
-                       if (global_opts.objective == rtedata) {
-                               mps_route_r(mps_file_in, mps_ver_in, &rte);
-                               skipMe = 0;
-                       }
-               }
+                       mps_route_r(mps_file_in, mps_ver_in, &rte);
+                       break;
 
-               if (recType == 'T')  {
+               case 'T':
                        /* Track record */
-                       if (global_opts.objective == trkdata) {
-                               mps_track_r(mps_file_in, mps_ver_in, &trk);
-                               skipMe = 0;
-                       }
-               }
+                       mps_track_r(mps_file_in, mps_ver_in, &trk);
+                       break;
 
-               if (recType == 'V')  {
+               case 'V':
                        /* Mapset record */
                        mps_mapsetname_r(mps_file_in, mps_ver_in);
-                       skipMe = 0;
                        /* Last record in the file */
+                       morework = 0;
                        break;
-               }
-
-               if (skipMe == 1) {
+               default:
+                       /* Unknown record type.  Skip over it. */
                        fseek(mps_file_in, reclen, SEEK_CUR); 
                }
+
        }       /* while (!feof(mps_file_in)) */
 
 #ifdef DUMP_ICON_TABLE
@@ -1669,7 +1658,7 @@ mps_write(void)
                                fread(&recType, 1, 1, mps_file_temp);
                        }
                }
-               route_disp_all(mps_trackhdr_w_wrapper, mps_noop, mps_trackdatapoint_w_wrapper);
+               track_disp_all(mps_trackhdr_w_wrapper, mps_noop, mps_trackdatapoint_w_wrapper);
        }
 
        if (mpsmergeout) {
index a71527ed8ea33383915b498252b281a55c8d25e4..b3f99e199dd0bb2d79800c33363f39743c00dac6 100755 (executable)
@@ -601,7 +601,7 @@ psit_track_r(FILE *psit_file, route_head **trk)
                                        track_head->rte_name = xstrdup(trkname);
                                }
                                trk_num++;
-                               route_add_head(track_head);
+                               track_add_head(track_head);
                        }
 
                        thisWaypoint->creation_time = dateTime;
@@ -795,7 +795,7 @@ psit_write(void)
                route_disp_all(psit_routehdr_w_wrapper, psit_noop, psit_waypoint_w_wrapper);
        }
        if (global_opts.objective == trkdata) {
-               route_disp_all(psit_trackhdr_w_wrapper, psit_noop, psit_trackdatapoint_w_wrapper);
+               track_disp_all(psit_trackhdr_w_wrapper, psit_noop, psit_trackdatapoint_w_wrapper);
        }
 
        mkshort_del_handle(mkshort_handle);
index 6c85a3bf8d425208883f555c89b84637260d54d9..3841d35213b2f5f64824666359662b023c00e614 100644 (file)
@@ -21,6 +21,7 @@
 #include "defs.h"
 
 static queue my_route_head;
+static queue my_track_head;
 static int rte_head_ct;
 static int rte_waypts;
 
@@ -28,6 +29,7 @@ void
 route_init(void)
 {
        QUEUE_INIT(&my_route_head);
+       QUEUE_INIT(&my_track_head);
 }
 
 unsigned int
@@ -61,6 +63,13 @@ route_add_head(route_head *rte)
        rte_head_ct++;
 }
 
+void
+track_add_head(route_head *rte)
+{
+       ENQUEUE_TAIL(&my_track_head, &rte->Q);
+       QUEUE_INIT(&rte->waypoint_list);
+}
+
 void
 route_add_wpt(route_head *rte, waypoint *wpt)
 {
@@ -118,11 +127,11 @@ route_reverse(const route_head *rte_hd)
        }
 }
 
-void 
-route_disp_all(route_hdr rh, route_trl rt, waypt_cb wc)
+void
+common_disp_all(queue *qh, route_hdr rh, route_trl rt, waypt_cb wc)
 {
        queue *elem, *tmp;
-       QUEUE_FOR_EACH(&my_route_head, elem, tmp) {
+       QUEUE_FOR_EACH(qh, elem, tmp) {
                const route_head *rhp;
                rhp = (route_head *) elem;
                if (rh) (*rh)(rhp);
@@ -130,6 +139,19 @@ route_disp_all(route_hdr rh, route_trl rt, waypt_cb wc)
                if (rt) (*rt)(rhp);
        }
 }
+
+void 
+route_disp_all(route_hdr rh, route_trl rt, waypt_cb wc)
+{
+       common_disp_all(&my_route_head, rh, rt, wc);
+}
+
+void 
+track_disp_all(route_hdr rh, route_trl rt, waypt_cb wc)
+{
+       common_disp_all(&my_track_head, rh, rt, wc);
+}
+
 void
 route_flush(queue *head)
 {
@@ -146,5 +168,6 @@ void
 route_flush_all()
 {
        route_flush(&my_route_head);
+       route_flush(&my_track_head);
 }
 
index 879a291f94a9b91625a66d89ce653020762be4c2..5e2831db6e3457ea4edd3798d3f4d8feb20420ea 100644 (file)
@@ -192,10 +192,9 @@ waypt_flush( queue *head )
 {
        queue *elem, *tmp;
 
-       queue *q;
        QUEUE_FOR_EACH(head, elem, tmp) {
-               q = dequeue(elem);
-               waypt_free((waypoint *) q);
+               waypoint *q = (waypoint *) dequeue(elem);
+               waypt_free(q);
        }
 }